//
// Created by Administrator on 2023/7/31.
//
#include <string>
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int countPoints(string rings) {
        vector<vector<bool>> record(10, vector<bool>(3, false));
        for (int i = 0; i < rings.size(); i += 2) {
            int n = int(rings[i + 1]-'0');
            if (rings[i] == 'R')
                record[n][0] = true;
            else if (rings[i] == 'G')
                record[n][1] = true;
            else
                record[n][2] = true;
        }
        int count = 0;
        for (int i = 0; i < 10; ++i) {
            if (record[i][0] && record[i][1] && record[i][2])
                count++;
        }
        return count;
    }
};
class Solution2 {
public:
    int countPoints(string rings) {
        int n = rings.size();
        vector<int> status(10);   // 状态数组
        // 遍历颜色位置对维护状态数组
        for (int i = 0; i < n; i += 2) {
            int idx = rings[i+1] - '0';
            if (rings[i] == 'R') {
                status[idx] |= 1;
            }
            else if (rings[i] == 'G') {
                status[idx] |= 2;
            }
            else {
                status[idx] |= 4;
            }
        }
        // 统计集齐三色环的杆的数量
        int res = 0;
        for (int i = 0; i < 10; ++i) {
            if (status[i] == 7) {
                ++res;
            }
        }
        return res;
    }
};


int main() {
    Solution s;
    cout << s.countPoints("B0B6G0R6R0R6G9") << endl;
}
